<?php
/**
 * Ajax请求
 * www.fangcms.com
 * User: fangcms
 */
namespace Wap\Controller;
use Org\Yike\Category;
class AjaxController extends CommonController{
    public function _initialize(){
        parent::_initialize();
        $this->user_id = session('userInfo.id');
    }

    //添加问答
    public function addAsk(){
        $title = I('post.title','');
        $info = I('post.info','');
        $name = I('post.name','');
        $phone = I('post.phone','');
        if($title==''){
            die(json_encode(array('status'=>0,'msg'=>'问答标题不能为空!')));
        }
        $_POST['cate_id'] = intval($_POST['cate_id']);
        $_POST['house_id'] = intval($_POST['house_id']);
        $_POST['user_id'] = $this->user_id;
        $_POST['title'] = trim($title);
        $_POST['info'] = strip_tags($info);
        $_POST['name'] = strip_tags($name);
        $_POST['phone'] = strip_tags($phone);
        $_POST['answer_user_id'] = intval($_POST['answer_user_id']);
        $_POST['add_time'] = time();
        $_POST['status'] = 1;
        M('ask')->create();
        if(M('ask')->add()){
            if($_POST['house_id']){
                M('house_info')->where(array('house_id'=>$_POST['house_id']))->setInc('ask',1);
            }
            die(json_encode(array('status'=>1,'msg'=>'您的问答提交成功')));
        }else{
            die(json_encode(array('status'=>0,'msg'=>'您的问答提交失败')));
        }
    }

    //回答问题
    public function addAnswer(){
        $ask_id = intval($_POST['ask_id']);
        $info = I('post.info','');
        if(!$this->user_id){
            die(json_encode(array('status'=>0,'msg'=>'您还没有登录,不能进行回答')));
        }
        if(!$ask_id){
            die(json_encode(array('status'=>0,'msg'=>'找不到对应的ID信息')));
        }
        $ask = M('ask')->where(array('status'=>1,'id'=>$ask_id))->find();
        if(!$ask['id']){
            die(json_encode(array('status'=>0,'msg'=>'找不到对应的ID问题信息')));
        }
        $_POST['ask_id'] = $ask_id;
        $_POST['info'] = strip_tags($info);
        $_POST['user_id'] = $this->user_id;
        $_POST['add_time'] = time();
        $_POST['status'] = 0;
        M('answer')->create();
        if(M('answer')->add()){
            M('ask')->where(array('id'=>$ask_id))->setInc('answer');
            die(json_encode(array('status'=>1,'msg'=>'您的问答提交成功')));
        }else{
            die(json_encode(array('status'=>0,'msg'=>'您的问答提交失败')));
        }
    }

    //回答列表顶起跟踩下
    public function topStep(){
        $id = intval($_POST['id']);
        $type = I('post.type','');
        /**
        if(!$this->user_id){
            die(json_encode(array('status'=>0,'msg'=>'您还没有登录,不能进行操作')));
        }**/
        if(!$id){
            die(json_encode(array('status'=>0,'msg'=>'找不到对应的ID信息')));
        }
        if(!in_array($type,array('top','step'))){
            die(json_encode(array('status'=>0,'msg'=>'不是有效的指令')));
        }
        $answer = M('answer')->where(array('status'=>1,'id'=>$id))->find();
        if(!$answer['id']){
            die(json_encode(array('status'=>0,'msg'=>'找不到对应的ID回答信息')));
        }

        //会员是否表示过
        if($this->user_id){
            $c = M('answer_count')->where(array('user_id'=>$this->user_id,'answer_id'=>$id))->count();
            if($c){
                die(json_encode(array('status'=>0,'msg'=>'您已经表示过该条回答信息了')));
            }
        }
        $answer_count = cookie('answer_count');
        if($answer_count == $id){
            die(json_encode(array('status'=>0,'msg'=>'您已经表示过该条回答信息了')));
        }
        $res = M('answer')->where(array('id'=>$id))->setInc($type);
        if($res){
            if($this->user_id){
                M('answer_count')->add(array('user_id'=>$this->user_id,'answer_id'=>$id));
            }else{
                cookie('answer_count',$id);
            }
            $count = M('answer')->where(array('id'=>$id))->getField($type);
            die(json_encode(array('status'=>1,'v'=>$count,'msg'=>'您的表示提交成功')));
        }else{
            die(json_encode(array('status'=>0,'msg'=>'您的表示提交成功')));
        }
    }

    //关注会员
    public function followUser(){
        $user_id = intval($_POST['id']);
        if(!$this->user_id){
            die(json_encode(array('status'=>0,'msg'=>'您还没有登录,不能进行会员关注')));
        }
        $user = M('user')->where(array('status'=>1,'id'=>$user_id))->find();
        if(!$user['id']){
            die(json_encode(array('status'=>0,'msg'=>'找不到对应的ID会员信息')));
        }
        if($this->user_id == $user['id']){
            die(json_encode(array('status'=>0,'msg'=>'自己不能关注自己')));
        }
        $user_follow = M('user_follow')->where(array('follow_id'=>$user_id,'user_id'=>$this->user_id))->find();
        if($user_follow['type']==1){
            die(json_encode(array('status'=>0,'msg'=>'您已经关注过该用户了')));
        }else{
            $_POST['type'] = 1;
        }

        $_POST['follow_id'] = $user['id'];
        $_POST['user_id'] = $this->user_id;
        $_POST['add_time'] = time();
        M('user_follow')->create();
        if(M('user_follow')->add()){
            die(json_encode(array('status'=>1,'msg'=>'关注会员成功')));
        }else{
            die(json_encode(array('status'=>0,'msg'=>'关注会员失败')));
        }
    }

    public function addPhone(){
        if($house_id = intval($_POST['house_id'])){
            $house = M('house')->where(array('status'=>1,'house_id'=>$house_id))->find();
            if(!$house['id']){
                die(json_encode(array('status'=>0,'msg'=>'找不到对应的楼盘信息')));
            }
            $_POST['phone'] = trim($_POST['phone']);
            $_POST['add_time'] = time();
            $_POST['type'] = 'dh';
            $_POST['status'] = 0;
            M('message')->create();
            if(M('message')->add()){
                die(json_encode(array('status'=>1,'msg'=>'免费电话提交成功')));
            }else{
                die(json_encode(array('status'=>0,'msg'=>'免费电话提交失败')));
            }
        }
    }

    //获取楼栋信息
    public function getProperty(){
        $house_id = intval($_POST['house_id']);
        $id = intval($_POST['id']);
        if(!$house_id or !$id){
            die(json_encode(array('status'=>0,'msg'=>'参数错误!')));
        }
        $property = M('property')->where(array('id'=>$id))->find();
        if(!$property){
            die(json_encode(array('status'=>0,'msg'=>'找不到对应的楼栋信息')));
        }

        if($property['house_type']){
            $house_type = M('house_type')->where(array('id'=>array('in',$property['house_type'])))->select();
            $str = '';
            if($house_type){
                foreach($house_type as $v){
                    $url = U('House/typeShow',array('hid'=>$v['house_id'],'id'=>$v['id']));
                    $str .= " <li>";
                    $str .= " <a target='_blank' href='{$url}'>";
                    $str .= " <span title='{$v['name']}' style='width:120px;'>{$v['name']}</span>";
                    $str .= " <span style='width:150px;'>{$v['room']}室{$v['hall']}厅{$v['toilets']}卫{$v['balcony']}阳台{$v['kitchen']}厨</span>";
                    $str .= " <span style='width:75px;'>{$v['area']}㎡</span>";
                    $str .= "</a>";
                    $str .= "</li>";
                }
            }
        }
        die(json_encode(array('status'=>1,'property'=>$property,'str'=>$str)));
    }

    //收藏
    public function collection(){
        $house_id = intval($_POST['house_id']);
        if(!$this->user_id){
            die(json_encode(array('status'=>0,'msg'=>'您还没有登录,不能进行收藏')));
        }
        $house = M('house')->where(array('status'=>1,'id'=>$house_id))->find();
        if(!$house['id']){
            die(json_encode(array('status'=>0,'msg'=>'找不到对应的ID楼盘信息')));
        }
        $count = M('house_collection')->where(array('user_id'=>$this->user_id,'house_id'=>$house_id))->count();
        if($count){
            die(json_encode(array('status'=>0,'msg'=>'您已收藏过该楼盘')));
        }
        $_POST['house_id'] = $house_id;
        $_POST['user_id'] = $this->user_id;
        $_POST['add_time'] = time();
        M('house_collection')->create();
        if(M('house_collection')->add()){
            M('house_info')->where(array('house_id'=>$house_id))->setInc('collection');
            die(json_encode(array('status'=>1,'msg'=>'收藏楼盘成功')));
        }else{
            die(json_encode(array('status'=>0,'msg'=>'收藏楼盘失败')));
        }
    }

    //中意
    public function italy(){
        $house_id = intval($_POST['house_id']);
        if(!$this->user_id){
            die(json_encode(array('status'=>0,'msg'=>'您还没有登录,不能进行中意操作')));
        }
        $house = M('house')->where(array('status'=>1,'id'=>$house_id))->find();
        if(!$house['id']){
            die(json_encode(array('status'=>0,'msg'=>'找不到对应的ID楼盘信息')));
        }
        $count = M('house_italy')->where(array('user_id'=>$this->user_id,'house_id'=>$house_id))->count();
        if($count){
            die(json_encode(array('status'=>0,'msg'=>'您已中意过该楼盘')));
        }
        $_POST['house_id'] = $house_id;
        $_POST['user_id'] = $this->user_id;
        $_POST['add_time'] = time();
        M('house_italy')->create();
        if(M('house_italy')->add()){
            M('house_info')->where(array('house_id'=>$house_id))->setInc('italy');
            die(json_encode(array('status'=>1,'msg'=>'中意楼盘成功')));
        }else{
            die(json_encode(array('status'=>0,'msg'=>'中意楼盘失败')));
        }
    }

    //选房单
    public function chooseRoom(){
        $this->display();
    }

    //举报
    public function report(){
        $this->display();
    }

    //新房插入
    public function orderHouse(){
        $data = array();
        $data['type'] = intval($_POST['type']);
        $data['house_id'] = intval($_POST['house_id']) ? intval($_POST['house_id']) : intval($_POST['id']);
        $data['group_id'] = intval($_POST['group_id']);
        $data['name'] = trim(I('post.name'));
        $data['phone'] = I('post.phone');
        if($data['type'] && $data['house_id']){
            if(!is_numeric($data['phone'])){
                die(json_encode(array('status'=>0,'msg'=>'手机号码输入有误')));
            }
            $data['add_time'] = time();
            $data['user_id'] = $this->user_id;
            $data['remarks'] = strip_tags(I('post.remarks'));
            if($data['type']==4 && !$data['group_id']){
                $group = M('group')->where(array('house_id'=>$data['house_id']))->order('id desc')->find();
                $data['group_id'] = $group['id'];
            }

            $msg = order_type('house',$data['type']);
            if(M('order_house')->add($data)){
                die(json_encode(array('status'=>1,'msg'=>'您的'.$msg.'提交成功!')));
            }else{
                die(json_encode(array('status'=>0,'msg'=>'您的'.$msg.'提交失败!')));
            }
        }else{
            die(json_encode(array('status'=>0,'msg'=>'参数错误')));
        }
    }

    //二手房插入
    public function orderUsed(){
        $data = array();
        $data['type'] = intval($_POST['type']);
        $data['used_id'] = intval($_POST['id']);
        $data['name'] = trim(I('post.name'));
        $data['phone'] = I('post.phone');
        $used = M('used')->where(array('id'=>$data['used_id']))->find();
        if(!$used){
            die(json_encode(array('status'=>0,'msg'=>'找不到对应的二手房信息')));
        }
        $data['store_id'] = $used['user_id'];
        if($data['type'] && $data['used_id']){
            if(!is_numeric($data['phone'])){
                die(json_encode(array('status'=>0,'msg'=>'手机号码输入有误')));
            }
            $data['add_time'] = time();
            $data['user_id'] = $this->user_id;
            $data['remarks'] = strip_tags(I('post.remarks'));
            $msg = order_type('used',$data['type']);
            if(M('order_used')->add($data)){
                die(json_encode(array('status'=>1,'msg'=>'您的'.$msg.'提交成功!')));
            }else{
                die(json_encode(array('status'=>0,'msg'=>'您的'.$msg.'提交失败!')));
            }
        }else{
            die(json_encode(array('status'=>0,'msg'=>'参数错误')));
        }
    }

    //二手房插入
    public function orderRental(){
        $data = array();
        $data['type'] = intval($_POST['type']);
        $data['rental_id'] = intval($_POST['id']);
        $data['name'] = trim(I('post.name'));
        $data['phone'] = I('post.phone');
        $rental = M('rental')->where(array('id'=>$data['rental_id']))->find();
        if(!$rental){
            die(json_encode(array('status'=>0,'msg'=>'找不到对应的出租房信息')));
        }
        $data['store_id'] = $rental['user_id'];
        if($data['type'] && $data['rental_id']){
            if(!is_numeric($data['phone'])){
                die(json_encode(array('status'=>0,'msg'=>'手机号码输入有误')));
            }
            $data['add_time'] = time();
            $data['user_id'] = $this->user_id;
            $data['remarks'] = strip_tags(I('post.remarks'));
            $msg = order_type('rental',$data['type']);
            if(M('order_rental')->add($data)){
                die(json_encode(array('status'=>1,'msg'=>'您的'.$msg.'提交成功!')));
            }else{
                die(json_encode(array('status'=>0,'msg'=>'您的'.$msg.'提交失败!')));
            }
        }else{
            die(json_encode(array('status'=>0,'msg'=>'参数错误')));
        }
    }

    private  function getHouse(){
        $id = intval($_GET['id']);
        if(!$id){
            $this->error('参数错误!');
        }
        $house = M('house')->where(array('id'=>$id))->find();
        if(!$house['id']){
            $this->error('找不到对应的楼盘信息');
        }
        $this->info = $house;
        return $house;
    }

    private  function getUsed(){
        $id = intval($_GET['id']);
        if(!$id){
            $this->error('参数错误!');
        }
        $house = M('used')->where(array('id'=>$id))->find();
        if(!$house['id']){
            $this->error('找不到对应的二手房信息');
        }
        $this->info = $house;
    }

    private  function getRental(){
        $id = intval($_GET['id']);
        if(!$id){
            $this->error('参数错误!');
        }
        $house = M('rental')->where(array('id'=>$id))->find();
        if(!$house['id']){
            $this->error('找不到对应的出租信息');
        }
        $this->info = $house;
    }

    //免费电话
    public function rentalTel(){
        $this->getRental();
        $this->display();
    }

    //小区预约看房
    public function rentalBook(){
        $this->getRental();
        $this->display();
    }

    //免费电话
    public function usedTel(){
        $this->getUsed();
        $this->display();
    }

    //团购报名
    public function buying(){
        $info = $this->getHouse();
        $this->group = M('group')->where(array('house_id'=>$info['id']))->order('id desc')->find();
        $this->display();
    }

    //免费电话
    public function houseTel(){
        $this->getHouse();
        $this->display();
    }

    //二手房预约房东
    public function usedBook(){
        $this->getUsed();
        $this->display();
    }

    //降价通知
    public function housePrice(){
        $this->getHouse();
        $this->display();
    }

    //报名看房
    public function houseLook(){
        $this->getHouse();
        $this->display();
    }

    //按居获取房型列表
    public function houseTypeRoom(){
        $house_id = intval($_POST['house_id']);
        $room = intval($_POST['room']);
        $type = intval($_POST['type']);
        if(!$house_id or !$room){
            die(json_encode(array('status'=>0,'msg'=>'参数错误')));
        }
        $house_type = M('house_type')->where(array('status'=>1,'house_id'=>$house_id,'room'=>$room))->order('area asc')->select();
        if(!$house_type){
            die(json_encode(array('status'=>0,'msg'=>'找不到对应的房型信息')));
        }else{
            if($type==1){
                $str = '';
                foreach($house_type as $v){
                    $url = U('House/typeShow',array('hid'=>$v['house_id'],'id'=>$v['id']));
                    $str .= "<tr>";
                    $str .= "<td height='37'><a href=".$url." title='{$v['name']}'>{$v['name']}</a></td>";
                    $str .= "<td height='37'>{$v['room']}室{$v['hall']}厅{$v['toilets']}卫{$v['balcony']}阳台{$v['kitchen']}厨</td>";
                    $str .= "<td height='37'>{$v['area']}㎡</td>";
                    $str .= "</tr>";
                }
                die(json_encode(array('status'=>1,'data'=>$str)));
            }else{
                die(json_encode(array('status'=>1,'data'=>$house_type)));
            }
        }
    }

    //获取房型列表
    public function getHouseList(){
        $area_id = intval($_POST['area_id']);
        $area_ids = intval($_POST['area_ids']);
        $room_type = intval($_POST['house_type']);
        $theme = intval($_POST['theme']);
        $key = trim($_POST['key']);
        $sort = intval($_POST['sort']);
        $where = array('status'=>1);
        if($key){
            $where['title'] = array('like','%'.$key.'%');
        }else{
            if($area_ids){
                $where['area_id'] = $area_ids;
            }else{
                $cate = new Category();
                $house_cate = M('house_cate')->where(array('status'=>1))->order('id desc')->select();
                $ids = $cate->getChiIds($house_cate,$area_id,1);
                array_push($ids,$area_id);
                $where['area_id'] = array('in',$ids);
            }
            if($room_type){
                $where['room_type'] = array('like','%|'.$room_type.'|%');
            }
            if($theme){
                $where['tags'] = array('like','%|'.$theme.'|%');
            }
        }
        $order = $this->sortWhere($sort);
        $field = 'id,title,tel,address,map,img,group_discount,discount,average_price';
        $list = M('house')->where($where)->field($field)->order($order)->select();
        die(json_encode(array('status'=>1,'data'=>array('d'=>$list))));
    }

    //获取二手和出租房列表
    public function getUsedRentalList(){
        $type = I('post.type');
        $area_id = intval($_POST['area_id']);
        $area_ids = intval($_POST['area_ids']);
        $room = intval($_POST['room']);
        $hall = intval($_POST['hall']);
        $kitchen = intval($_POST['kitchen']);
        $toilet = intval($_POST['toilet']);
        $key = trim($_POST['key']);
        $sort = intval($_POST['sort']);
        $where = array('status'=>1);
        if($key){
            $where['title'] = array('like','%'.$key.'%');
        }else{
            if($area_ids){
                $where['area_id'] = $area_ids;
            }else{
                $cate = new Category();
                $house_cate = M('house_cate')->where(array('status'=>1))->order('id desc')->select();
                $ids = $cate->getChiIds($house_cate,$area_id,1);
                array_push($ids,$area_id);
                $where['area_id'] = array('in',$ids);
            }
            if($room){
                $where['room'] = array('eq',$room);
            }
            if($hall){
                $where['hall'] = array('eq',$hall);
            }
            if($kitchen){
                $where['kitchen'] = array('eq',$kitchen);
            }
            if($toilet){
                $where['toilet'] = array('eq',$toilet);
            }
        }
        $order = $this->sortWhere($sort);
        $list = M($type)->where($where)->order($order)->select();
        die(json_encode(array('status'=>1,'data'=>array('d'=>$list))));
    }

    //获取新房分类
    public function getHouseCate(){
        $pid = intval($_POST['pid']);
        $list = M('house_cate')->where(array('status'=>1,'pid'=>$pid))->field('id,name,pid')->order('ordid desc')->select();
        die(json_encode(array('status'=>1,'list'=>$list)));
    }
    //获取出租房、二手房分类
    public function getAreaCate(){
        $pid = intval($_POST['pid']);
        $list = M('area_cate')->where(array('status'=>1,'pid'=>$pid))->field('id,name,pid')->order('ordid desc')->select();
        die(json_encode(array('status'=>1,'list'=>$list)));
    }

    //获取推荐位
    public function getPosition(){
        $cate_id = intval($_POST['cate_id']);
        if(!$cate_id){
            die(json_encode(array('status'=>0,'msg'=>'参数错误')));
        }
        $cate = M('position_cate')->where(array('id'=>$cate_id))->find();
        $list = getPosition($cate_id,8);
        if(!$list[$cate_id]){
            die(json_encode(array('status'=>0,'msg'=>'找不到对应的楼盘信息')));
        }
        return  die(json_encode(array('status'=>1,'list'=>$list[$cate_id],'model'=>$cate['model'])));
    }

    public function getAsk(){
        $bid = intval($_POST['bid']);
        $list = M('ask')->where(array('status'=>1))->limit(8)->order('rand()')->select();
        $cate = cateFor('','ask_cate');
        $html = '';
        foreach($list as $v){
            $html .= '<li><a href="'.U('Ask/detail',array('id'=>$v['id'])).'"><span class="org">【'.$cate[$v['cate_id']].'】</span>'.$v['title'].'</a></li>';
        }
        die(json_encode(array('status'=>1,'html'=>$html,'bid'=>$bid+1)));
    }

    //排序
    private function sortWhere($key){
        $key = $key ? $key : 1;
        $arr = array(
            1=>'id desc',
            2=>'id asc',
            3=>'is_rec desc',
            4=>'is_rec asc',
            5=>'average_price desc',
            6=>'average_price asc',
            7=>'price desc',
            8=>'price asc'
        );
        return $arr[$key] ;
    }
    //手机端自动填充
    public function autoEstate (){
        $title = urldecode (I ('get.term', ''));
        $map['yk_estate.title'] = array('like', '%'.$title.'%');
        $map['_logic'] = 'OR';
        $map['yk_estate.alias'] = array('like', '%'.$title.'%');
        $map['yk_estate.short'] = array('like', '%'.$title.'%');
        $data = M ('estate')
            ->field('yk_estate.id,yk_estate.title,yk_area_cate.id as area_id,yk_area_cate.name as area,bu.bid,bu.alias')
            ->join('yk_area_cate on yk_estate.area_id = yk_area_cate.id', 'LEFT')
            ->join('yk_build bu on bu.estate_id = yk_estate.id', 'RIGHT')
            ->where($map)
            ->select();
        foreach ($data as $i=>$d){
            $res[$d['id']]['label'] = $d['title'];
            $res[$d['id']]['value'] = $d['id'];
            $res[$d['id']]['area'] = $d['area'];
            $res[$d['id']]['area_id'] = $d['area_id'];
            $res[$d['id']]['build'][] = array ('bid'=>$d['bid'],'alias'=>$d['alias']);

        }
        if (!empty ($res)){
            exit (json_encode ($res));
        }
        exit (json_encode(''));
    }
    //获取单元
    public function getUnit (){
        $bid = I ('post.id');
        $units = M ('unit')->where ("build={$bid}")->select ();
        $count = count ($units);
        if($units){
            die(json_encode(array('state'=>'ok','data'=>$units,'msg'=>'获取成功','count'=>$count)));
        }else{
            die(json_encode(array('state'=>0,'msg'=>'获取失败')));
        }
    }
    //获取房间
    public function getRoom (){
        $unid = I ('post.id');
        $rooms = M ('room')->where ("unit={$unid}")->select ();
        if($rooms){
            die(json_encode(array('state'=>'ok','data'=>$rooms,'msg'=>'获取成功')));
        }else{
            die(json_encode(array('state'=>0,'msg'=>'获取失败')));
        }
    }
    //查看业主信息
    public function view (){
        $used_id = I ('post.used_id', '');
        $field = I ('post.field', '');
        $mod = M ('user');
        $user_id = session('userInfo.id');
        $info = M ('used')->where (array ('id'=>$used_id))->getField($field);
        //检查经纪人查看业主信息的今天次数
        $userInfo = $mod->field ('view_time,view_freq')->where ('id='.$user_id)->find ();
        $today = date ('Y-m-d');
        if ($today.' 00:00:00' != $userInfo['view_time']){
            $mod->where (array ('id'=>$user_id))->setField (array ('view_time'=>$today,'view_freq'=>1));
        }elseif($userInfo['view_freq'] < 10){
            $mod->where (array ('id'=>$user_id))->setInc ('view_freq');
        }else{
            exit (json_encode(array ('state'=>2,'text'=>'你当天查看次数已用完')));
        }

        //检查经纪人有没有跟进房源
        $starTime = strtotime ($today." 00:00:00");
        $endTime = strtotime ($today." 23:59:59");
        $f_mod = M ('follow');
        $follow = $f_mod->where (array ('user_id'=>$user_id, 'discuss'=>'未跟进', 'add_time' =>array ('between', array ($starTime,$endTime+1))))->select ();
        if (empty ($follow)){
            $follow_data = array (
                'user_id' => $user_id,
                'source_id' => $used_id,
                'uname' => session('userInfo.username'),
                'discuss' => '未跟进',
                'add_time' => time ()
            );
            $f_mod->add ($follow_data);
        }else{
            exit (json_encode(array ('state'=>3,'text'=>'请完善上次查看业主跟进信息')));
        }

        if (! empty($info)){
            exit (json_encode(array ('state'=>1,'text'=>$info)));
        }
        exit (json_encode(array ('state'=>0,'text'=>'')));
    }
}